﻿Public Class Form3

    sub New()
        'ClsWebbutil.SetWebBrowserFeatures(11)
        ' 此调用是设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。

        me.webBrowser1.AllowWebBrowserDrop = false
        CheckForIllegalCrossThreadCalls =false

        Dim nativeBrowser = DirectCast(webBrowser1.ActiveXInstance, SHDocVw.WebBrowser)

        WebBrowser1.Navigate("learning.hzrs.hangzhou.gov.cn")

'        WebBrowser1.Navigate("https://ie.icoa.cn/")

        AddHandler nativeBrowser.NewWindow2, AddressOf Form1_NewWindow2

    End Sub

    Property frm as Form3
    ’ 一次可以传递一个string
    Public Delegate Sub DataChangeHandler(sender As Object, args As DataChangeEventArgs)

    Public Event DataChange As DataChangeHandler
    Public  Property doc As System.Windows.Forms.HTMLDocument
    Private Sub Form1_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean)
        frm=new Form3()
        '事先建好一个带WebBrowser的窗体
        ppDisp = frm.webBrowser1.ActiveXInstance
        AddHandler frm.DataChange, Addressof DataChanged
        frm.Text="视频窗口"
        doc=frm.WebBrowser1.Document
                
        frm.Show()
        doc=frm.WebBrowser1.Document
        texthis(frm.WebBrowser1.DocumentText)

        'frm.Visible = False

    End Sub
    
    Public Sub DataChanged(sender As Object, args As DataChangeEventArgs)

        '更新窗体控件
'
'        If args.name = ("closed") Then
'            csEndTime = System.DateTime.Now
'            csts = csEndTime.Subtract(csStartTime)
'
'            If csts.TotalSeconds < 300 and csts.TotalSeconds<coursetime*60 Then
'                texthis("视频未学习完成课程，间隔时间" + csts.Seconds.ToString() + "秒", True)
'
'            Else
'
'                texthis("已经成功学习完成一门课程，子窗口已关闭", True)
'                childWb = False
''                Me.disp()
'                Me.Close()
'
'            End If
'
'        ElseIf args.name = ("msg") Then
'            OnDataChange(Me, New DataChangeEventArgs("msg", args.pass))
'
'        End If

    End Sub
    ''' <summary>
    ''' 日志和显示历史消息
    ''' </summary>
    ''' <param name="msg"></param>
    Private Sub texthis(byval msg As string)
        dim tim = DateTime.Now.tostring("yyyy-MM-dd HH:mm:ss")
        dim ms = tim & vbTab & vbTab & msg & vbCrLf 


'        log.WriteLog(ms)

'        RtbHis.SelectionStart = RtbHis.Text.Length
        If Not ms.StartsWith("已经学完20节课程") Then
            RichTextBox1.Text=ms+RichTextBox1.Text
        End If
        

'        RtbHis.Text+=ms
        
'        msEndTime =Now
'        msts =msEndTime.Subtract(msStartTime)
'
'        if msts.TotalSeconds>5  then
'
'            RtbHis.SelectionStart = RtbHis.Text.Length
'            RtbHis.ScrollToCaret()
'            msStartTime=Now
'        End If
'        
        
        

    End Sub


End Class